<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
	$('#outboundTable').bootstrapTable({
		 
		  //请求方法
               method: 'get',height:550,
               //类型json
               dataType: "json",
               //显示刷新按钮
               showRefresh: true,
               //显示切换手机试图按钮
               showToggle: true,
               //显示 内容列下拉框
    	       showColumns: true,
    	       //显示到处按钮
    	       showExport: true,
    	       //显示切换分页按钮
    	       showPaginationSwitch: true,
    	       //显示详情按钮
    	       detailView: true,
    	       	//显示详细内容函数
	           detailFormatter: "detailFormatter",
    	       //最低显示2行
    	       minimumCountColumns: 2,
               //是否显示行间隔色
               striped: true,
               //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
               cache: false,    
               //是否显示分页（*）  
               pagination: true,   
                //排序方式 
               sortOrder: "asc",  
               //初始化加载第一页，默认第一页
               pageNumber:1,   
               //每页的记录行数（*）   
               pageSize: 10,  
               //可供选择的每页的行数（*）    
               pageList: [10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
               url: "${ctx}/wms/outbound/data1",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',   
               ////查询参数,每次调用是会带上这个参数，可自定义                         
               queryParams : function(params) {
               	var searchParam = $("#searchForm").serializeJSON();
               	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
               	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
               	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                   return searchParam;
               },
               //分页方式：client客户端分页，server服务端分页（*）
               sidePagination: "server",
               contextMenuTrigger:"right",//pc端 按右键弹出菜单
               contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
               contextMenu: '#context-menu',
               onContextMenuItem: function(row, $el){
                   if($el.data("item") == "edit"){
                   	edit(row.id);
                   } else if($el.data("item") == "delete"){
                        jp.confirm('确认要删除该出库单记录吗？', function(){
                       	jp.loading();
                       	jp.get("${ctx}/wms/outbound/delete?id="+row.id, function(data){
                   	  		if(data.success){
                   	  			$('#outboundTable').bootstrapTable('refresh');
                   	  			jp.success(data.msg);
                   	  		}else{
                   	  			jp.error(data.msg);
                   	  		}
                   	  	})
                   	   
                   	});
                      
                   } 
               },
              
               onClickRow: function(row, $el){
               },
               columns: [{
		        checkbox: true
		       
		    }
			,{
		        field: 'code',
		        title: '出库单号',
		        sortable: true
		        ,formatter:function(value, row , index){
		        	return "<a href='javascript:edit(\""+row.id+"\")'>"+value+"</a>";
		         }
		       
		    }
			,{
		        field: 'status',
		        title: '状态',
		        sortable: true
		       
		    }
			,{
		        field: 'type',
		        title: '出库类型',
		        sortable: true,

                       formatter:function(value, row , index){
                           return jp.getDictLabel(${fns:toJson(fns:getDictList('delivery_type'))}, value, "-");
                       }
		       
		    }
			,{
		        field: 'date',
		        title: '订单日期',
		        sortable: true
		       
		    }
			,{
		        field: 'ownerCode',
		        title: '货主代码',
		        sortable: true
		       
		    }
			,{
		        field: 'entrustNumber',
		        title: '销售订单号',
		        sortable: true
		       
		    }
			,{
		        field: 'deliveryTime',
		        title: '要求发货日期',
		        sortable: true
		       
		    }
			,{
		        field: 'amount',
		        title: '总订购量',
		        sortable: true
		       
		    }
			,{
		        field: 'externalOrder',
		        title: '外部订单号',
		        sortable: true
		       
		    }
			,{
		        field: 'actualDeliveryTime',
		        title: '实际发货日期',
		        sortable: true
		       
		    }
			,{
		        field: 'grossWeight',
		        title: '总毛重',
		        sortable: true
		       
		    }
			,{
		        field: 'volume',
		        title: '总体积',
		        sortable: true
		       
		    }
			,{
		        field: 'erpOrder',
		        title: '提货单号',
		        sortable: true
		       
		    }
			,{
		        field: 'arrivalTime',
		        title: '到货日期',
		        sortable: true
		       
		    }
			,{
		        field: 'netWeight',
		        title: '总净重',
		        sortable: true
		       
		    }
			,{
		        field: 'money',
		        title: '总金额',
		        sortable: true
		       
		    }
			,{
		        field: 'shipmentNumbers',
		        title: '装运单号',
		        sortable: true
		       
		    }
			,{
		        field: 'workNumber',
		        title: '作业单号',
		        sortable: true
		       
		    }
			,{
		        field: 'no',
		        title: '箱数',
		        sortable: true
		       
		    }
			,{
		        field: 'loadingType',
		        title: '装卸类型',
		        sortable: true
		       
		    }
			,{
		        field: 'moveType',
		        title: '移动类型',
		        sortable: true
		       
		    }
			,{
		        field: 'logisticsName',
		        title: '物流商名称',
		        sortable: true
		       
		    }
			,{
		        field: 'logisticsPerson',
		        title: '联系人',
		        sortable: true
		       
		    }
			,{
		        field: 'logisticsPhone',
		        title: '联系人电话',
		        sortable: true
		       
		    }
			,{
		        field: 'plateNumber',
		        title: '车牌号码',
		        sortable: true
		       
		    }
			,{
		        field: 'driverPhone',
		        title: '司机电话',
		        sortable: true
		       
		    }
			,{
		        field: 'transportMode',
		        title: '运输方式',
		        sortable: true
		       
		    }
			,{
		        field: 'driverName',
		        title: '司机姓名',
		        sortable: true
		       
		    }
			,{
		        field: 'ownerName',
		        title: '货主名称',
		        sortable: true
		       
		    }
			,{
		        field: 'ownerAddress',
		        title: '地址',
		        sortable: true
		       
		    }
			,{
		        field: 'ownerPerson',
		        title: '联系人',
		        sortable: true
		       
		    }
			,{
		        field: 'ownerPhone',
		        title: '电话',
		        sortable: true
		       
		    }
			,{
		        field: 'logisticsOrder',
		        title: '物流订单号',
		        sortable: true
		       
		    }
			,{
		        field: 'ownerSystem',
		        title: '货主系统名称',
		        sortable: true
		       
		    }
			,{
		        field: 'unitName',
		        title: '收货单位名称',
		        sortable: true
		       
		    }
			,{
		        field: 'unitConfirmor',
		        title: '收货单位确认人',
		        sortable: true
		       
		    }
			,{
		        field: 'phone',
		        title: '确认人电话',
		        sortable: true
		       
		    }
			,{
		        field: 'site',
		        title: '收货详细地址',
		        sortable: true
		       
		    }
			,{
		        field: 'arriveProvince',
		        title: '到站省',
		        sortable: true
		       
		    }
			,{
		        field: 'arriveCity',
		        title: '到站市',
		        sortable: true
		       
		    }
			,{
		        field: 'distance',
		        title: '合同里程',
		        sortable: true
		       
		    }
			,{
		        field: 'transitLines',
		        title: '运输线路',
		        sortable: true
		       
		    }
			,{
		        field: 'remarks',
		        title: '备注信息',
		        sortable: true
		       
		    }
		     ]
		
		});
		
		  
	  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端

		 
		  $('#outboundTable').bootstrapTable("toggleView");
		}
	  
	  $('#outboundTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
            $('#remove').prop('disabled', ! $('#outboundTable').bootstrapTable('getSelections').length);
            $('#dayin').prop('disabled', $('#outboundTable').bootstrapTable('getSelections').length!=1);
            $('#edit').prop('disabled', ! $('#outboundTable').bootstrapTable('getSelections').length);
          $('#dayin1').prop('disabled', $('#outboundTable').bootstrapTable('getSelections').length!=1);
          $('#edit1').prop('disabled', ! $('#outboundTable').bootstrapTable('getSelections').length);
        });
		$("#btnImport").click(function(){
			jp.open({
			    type: 1, 
			    area: [500, 300],
			    title:"导入数据",
			    content:$("#importBox").html() ,
			    btn: ['下载模板','确定', '关闭'],
				    btn1: function(index, layero){
					  window.location='${ctx}/wms/outbound/import/template';
				  },
			    btn2: function(index, layero){
				        var inputForm =top.$("#importForm");
				        var top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe 
				        inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
				        inputForm.onsubmit = function(){
				        	jp.loading('  正在导入，请稍等...');
				        }
				        inputForm.submit();
					    jp.close(index);
				  },
				 
				  btn3: function(index){ 
					  jp.close(index);
	    	       }
			}); 
		});
		    
	  $("#search").click("click", function() {// 绑定查询按扭
		  $('#outboundTable').bootstrapTable('refresh');
		});
	 
	 $("#reset").click("click", function() {// 绑定查询按扭
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		   $("#searchForm  .select-item").html("");
		  $('#outboundTable').bootstrapTable('refresh');
		});
		
		
	});
		
  function getIdSelections() {
        return $.map($("#outboundTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }
function getsSelections() {
    return $.map($("#outboundTable").bootstrapTable('getSelections'), function (row) {
        return row.status
    });
}
  function fache() {
  	var status=getsSelections().toString().split(",");
  	for(var i=0;i<status.length;i++){
  		if(status[i]!="拣货完成"){
  			jp.warning("请选择拣货完成的订单");
  			return;
		}
	}
      jp.confirm('确认要发车吗？', function(){
          jp.loading();
          jp.get("${ctx}/wms/outbound/update?ids=" + getIdSelections(), function(data){
              if(data.success){
                  $('#outboundTable').bootstrapTable('refresh');
                  jp.success(data.msg);
              }else{
                  jp.error(data.msg);
              }
          })

	  })
	  
  }
function cd() {
    if(getsSelections()=="部分拣货"){
    jp.confirm('确认要拆单吗？', function(){
        jp.loading();
        jp.get("${ctx}/wms/outbound/cd?ids=" + getIdSelections(), function(data){
            if(data.success){
                $('#outboundTable').bootstrapTable('refresh');
                jp.success(data.msg);
            }else{
                jp.error(data.msg);
            }
        })
	})
}}

function fache1() {
    var status=getsSelections().toString().split(",");
    for(var i=0;i<status.length;i++){
        if(status[i]=="已创建"){
            jp.warning("请选择拣货的订单");
            return;
        }
    }
    jp.confirm('确认要发车吗？', function(){
        jp.loading();
        jp.get("${ctx}/wms/outbound/update1?ids=" + getIdSelections(), function(data){
            if(data.success){
                $('#outboundTable').bootstrapTable('refresh');
                jp.success(data.msg);
            }else{
                jp.error(data.msg);
            }
        })

    })

}
function cd1() {
    if(getsSelections()=="部分拣货"){
        jp.confirm('确认要拆单吗？', function(){
            jp.loading();
            jp.get("${ctx}/wms/outbound/cd1?ids=" + getIdSelections(), function(data){
                if(data.success){
                    $('#outboundTable').bootstrapTable('refresh');
                    jp.success(data.msg);
                }else{
                    jp.error(data.msg);
                }
            })
        })
    }}
  function deleteAll(){

		jp.confirm('确认要删除该出库单记录吗？', function(){
			jp.loading();  	
			jp.get("${ctx}/wms/outbound/deleteAll?ids=" + getIdSelections(), function(data){
         	  		if(data.success){
         	  			$('#outboundTable').bootstrapTable('refresh');
         	  			jp.success(data.msg);
         	  		}else{
         	  			jp.error(data.msg);
         	  		}
         	  	})
          	   
		})
  }
  
  function add(){
	  jp.openDialog('新增出库单', "${ctx}/wms/outbound/form",'1200px', '1000px', $('#outboundTable'));
  }
  
  function edit(id){//没有权限时，不显示确定按钮
  	  if(id == undefined){
			id = getIdSelections();
		}
	   <shiro:hasPermission name="wms:outbound:edit">
	  jp.openDialogView('编辑出库单', "${ctx}/wms/outbound/form?id=" + id,'1200px', '1000px', $('#outboundTable'));
	   </shiro:hasPermission>
	  <shiro:lacksPermission name="wms:outbound:edit">
	  jp.openDialogView('查看出库单', "${ctx}/wms/outbound/form?id=" + id,'1200px', '1000px', $('#outboundTable'));
	  </shiro:lacksPermission>
  }





function detailFormatter(index, row) {
    var htmltpl =  $("#outboundChildrenTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
    var html = Mustache.render(htmltpl, {
        idx:row.id
    });
    $.get("${ctx}/wms/outbound/detail?id="+row.id, function(outbound){

        var outboundChild1RowIdx = 0, outboundChild1Tpl = $("#outboundChild1Tpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
        var data1 =outbound.storehouseList;
        for (var i=0; i<data1.length; i++){
            addRow('#outboundChild-'+row.id+'-1-List', outboundChild1RowIdx, outboundChild1Tpl, data1[i]);
            outboundChild1RowIdx = outboundChild1RowIdx + 1;
        }

        var outboundChild2RowIdx = 0, outboundChild2Tpl = $("#outboundChild2Tpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
        var data2 =outbound.outStatisticsList;
        for (var i=0; i<data2.length; i++){
            addRow('#outboundChild-'+row.id+'-2-List', outboundChild2RowIdx, outboundChild2Tpl, data2[i]);
            outboundChild2RowIdx = outboundChild2RowIdx + 1;
        }


    })

    return html;
}

function addRow(list, idx, tpl, row){
    $(list).append(Mustache.render(tpl, {
        idx: idx, delBtn: true, row: row
    }));
}

function p() {
    return $.map($("#outboundTable").bootstrapTable('getSelections'), function (row) {
        return row.status
    });
}





</script>
<script type="text/template" id="outboundChildrenTpl">//<!--
    <div class="tabs-container">
    <ul class="nav nav-tabs">
    <li class="active"><a data-toggle="tab" href="#tab-{{idx}}-1" aria-expanded="true">出库物料明细</a></li>
    <li ><a data-toggle="tab" href="#tab-{{idx}}-2" aria-expanded="true">出库工作量统计</a></li>
    </ul>
    <div class="tab-content">
    <div id="tab-{{idx}}-2" class="tab-pane fade ">
    <table class="ani table">
    <thead>
    <tr>
    <th>职位</th>
    <th>姓名</th>
    <th>工作量</th>
    <th>备注信息</th>
    </tr>
    </thead>
    <tbody id="outboundChild-{{idx}}-2-List">
    </tbody>
    </table>
    </div>
    <div id="tab-{{idx}}-1" class="tab-pane fade in active">
    <table class="ani table">
    <thead>
    <tr>
    <th>物料名称</th>
    <th>物料编码</th>
    <th>包装</th>
    <th>单位</th>
    <th>订货数量</th>
    <th>拣货数量</th>
    </tr>
    </thead>
    <tbody id="outboundChild-{{idx}}-1-List">
    </tbody>
    </table>
    </div>
    </div>//-->
    </script>
    <script type="text/template" id="outboundChild2Tpl">//<!--
    <tr>
    <td>
    {{row.position.name}}
</td>
<td>
{{row.name.name}}
</td>
<td>
{{row.work}}
</td>
<td>
{{row.remarks}}
</td>
</tr>//-->
</script>
<script type="text/template" id="outboundChild1Tpl">//<!--
    <tr>
    <td>
    {{row.name.name}}
</td>
<td>
{{row.code}}
</td>
<td>
{{row.packing}}
</td>
<td>
{{row.unit}}
</td>

<td>
{{row.orderNumber}}
</td>

<td>
{{row.picking}}
</td>


</tr>//-->
</script>
